package com.fn.flutter_fn_sdk.page;

import android.app.Activity;
import android.util.Log;

import androidx.annotation.NonNull;

import com.fn.flutter_fn_sdk.event.AdEventAction;
import com.fn.sdk.api.interstitial.FnInterstitialAd;
import com.fn.sdk.api.interstitial.FnInterstitialAdListener;

import io.flutter.plugin.common.MethodCall;

/**
 * 插屏广告
 */
public class InterstitialPage extends BaseAdPage implements FnInterstitialAdListener {
    private final String TAG = InterstitialPage.class.getSimpleName();

    @Override
    public void loadAd(Activity activity, @NonNull MethodCall call) {
        Log.i(TAG, "loadAd");
        FnInterstitialAd fnInterstitialAd = new FnInterstitialAd();
        fnInterstitialAd.loadAd(activity,posId,this);
    }

    @Override
    public void onCached() {
        Log.i(TAG, "onCached");
        sendEvent(AdEventAction.onAdLoaded);
    }

    @Override
    public void onOpen() {
        Log.i(TAG, "onOpen");
        sendEvent(AdEventAction.onAdPresent);
    }

    @Override
    public void onExposure() {
        Log.i(TAG, "onExposure");
        sendEvent(AdEventAction.onAdExposure);
    }

    @Override
    public void onClick() {
        Log.i(TAG, "onClick");
        sendEvent(AdEventAction.onAdClicked);
    }

    @Override
    public void onClose() {
        Log.i(TAG, "onClose");
        sendEvent(AdEventAction.onAdClosed);
    }

    @Override
    public void onError(int i, String s, String s1) {
        Log.d(TAG, "onError adError:" + i+"s:"+s+"s1:"+s1);
        sendErrorEvent(i, s);
    }
}